/*
	HD-RP v0.1 Dev r15
	
	Credits to scripting goes to Florin and rAped.
	Some credits must go to Ole for fucking around making our lives misserable.

	# I will add more here later :)
*/

#define REVISION 15

#include <a_samp>
#include <a_mysql>
#include <a_players>
#include <utils>
//#include <dini>
//#include <morphinc>
//#include <core>
//#include <float>
//#include <time>
//#include <file>


#define COLOR_GRAD1 0xB4B5B7FF
#define COLOR_GRAD2 0xBFC0C2FF
#define COLOR_GRAD3 0xCBCCCEFF
#define COLOR_CORLEONE 0x212121AA
#define COLOR_GRAD4 0xD8D8D8FF
#define COLOR_GRAD5 0xE3E3E3FF
#define COLOR_GRAD6 0xF0F0F0FF
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_FADE1 0xE6E6E6E6
#define COLOR_FADE2 0xC8C8C8C8
#define COLOR_FADE3 0xAAAAAAAA
#define COLOR_FADE4 0x8C8C8C8C
#define COLOR_FADE5 0x6E6E6E6E
#define COLOR_PURPLE 0xC2A2DAAA
#define COLOR_DBLUE 0x2641FEAA
#define COLOR_BLACK 0x000000FF
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_OOC 0xE0FFFFAA
#define COLOR_BLUE 0x33FFFFFF
#define COLOR_RED 0xAA3333AA
#define COLOR_ADMINCHAT 0x6495EDFF
#define COLOR_TESTARED 0xFF4040FF
#define COLOR_LIGHTRED 0xFF6347AA
#define COLOR_LIGHTBLUE 0x33CCFFAA
#define COLOR_LIGHTGREEN 0x9ACD32AA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_YELLOW2 0xF5DEB3AA
#define COLOR_LIGHTYELLOW 0xF5DEB3AA
#define PLAYER_CONNECT 2
#define PLAYER_LOGIN 3
#define VEHICLE_LOAD 4


forward SetPlayerMoney(playerid, ammount);
forward OnPlayerRegister(playerid, password[]);
forward OnPlayerLogin(playerid, password[]);
forward Encrypt(string[]);
forward PingSQL();
forward ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5);
forward ProxDetectorS(Float:radi, playerid, targetid);
forward PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z);
forward ReTutorial(playerid);
forward SendAdminMessage(color, string[]);


new SQLPtr;
new realchat = 1;
new gPlayerAccount[MAX_PLAYERS];
new gPlayerLogged[MAX_PLAYERS];
enum pInfo
{
	pKey[56],
	pName[MAX_PLAYER_NAME],
   	pPass[128],
	pLevel,
	pMoney,
	pAdmin,
	pInt,
	pVirtual,
	pLocal
};
new PlayerInfo[MAX_PLAYERS][pInfo];

// Pickups
new BankEnter;
new BankExit;



main()
{
	print("\n----------------------------------");
	printf("               HD-RP Rev. %d", REVISION);
	print("----------------------------------\n");
}

public OnGameModeInit()
{
	new query[256];
	mysql_debug(1);
//    SQLPtr = mysql_connect("small.linuxnation.eu","andreash","hdrp","Ft86ywnXcN7548VB");
	SQLPtr = mysql_connect("127.0.0.1","root","hdrp","");
	SetTimer("PingSQL", 10000, 1);
	format(query, sizeof(query), "SELECT * FROM vehicles");
	mysql_query(query, VEHICLE_LOAD, 333, SQLPtr);
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
		SetTimerEx("OnPlayerUpdate", 60000, 1, "d", i);
	}
	SetGameModeText("HD-RP v0.1 Beta");
	AddPlayerClass(2, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
	
	// Non estate houses like PD, 24/7, Bank and so on...
    BankEnter = CreatePickup(1318, 1, 1462.395751,-1012.391174,26.843799);
    BankExit = CreatePickup(1318, 1, 2305.0930,-16.1713,26.7422);
    
	return 1;
}

public OnGameModeExit()
{
	new string[128];
    format(string, sizeof(string), "DELETE FROM vehicles WHERE type = '2'");
    mysql_query(string);
	return 1;
}

public SetPlayerMoney(playerid, ammount)
{
	ResetPlayerMoney(playerid);
	GivePlayerMoney(playerid, ammount);
	return 1;
}

public Encrypt(string[])
{
	for(new x=0; x < strlen(string); x++)
	{
		string[x] += (3^x) * (x % 15);
		if(string[x] > (0xff))
		{
			string[x] -= 256;
		}
	}
	return 1;
}

public ReTutorial(playerid)
{
    TogglePlayerControllable(playerid, 1);
//	SendClientMessageToAll(COLOR_LIGHTRED, "Sending player to tutorial.");
}

public SendAdminMessage(color, string[])
{
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
		if(IsPlayerConnected(i))
		{
		    if(PlayerInfo[i][pAdmin] >= 1)
		    {
				SendClientMessage(i, color, string);
			}
		}
	}
}

public PingSQL()
{
	if(mysql_ping(SQLPtr) == -1)
	{
		mysql_reconnect(SQLPtr);
	}
}
	

public OnPlayerRequestClass(playerid, classid)
{
	SetPlayerInterior(playerid,0);
	SetPlayerPos(playerid,-1657.5237,1207.6644,13.6719);
	SetPlayerFacingAngle(playerid,357.6906);
	
	SetPlayerCameraPos(playerid, -1657.4678,1211.2292,13.6781);
	SetPlayerCameraLookAt(playerid,-1657.5237,1207.6644,13.6719);
	
	return 1;
}

public OnPlayerRegister(playerid, password[])
{
	if(!IsPlayerConnected(playerid)) return 1;
	new query[256];
	format(query, sizeof(query), "INSERT INTO players (name, password, level, money, admin) VALUES ('%s', '%s', '1', '20000', '0')",PlayerInfo[playerid][pName],password);
	mysql_query(query);
	OnPlayerLogin(playerid, password);
	return 1;
}

public OnPlayerLogin(playerid, password[])
{
	if(!IsPlayerConnected(playerid)) return 1;
	new query[256];
	format(query, sizeof(query), "SELECT * FROM players WHERE name='%s'", PlayerInfo[playerid][pName]);
//	format(PlayerInfo[playerid][pKey], 56, "%s", password);
	strmid(PlayerInfo[playerid][pKey], password, 0, 56, 255);
	mysql_query(query, PLAYER_LOGIN, playerid, SQLPtr);
	return 1;
}

public OnPlayerUpdate(playerid)
{
	new query[256];
	SetPlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
	SetPlayerScore(playerid, PlayerInfo[playerid][pLevel]);
	SetPlayerInterior(playerid, PlayerInfo[playerid][pInt]);
	format(query, sizeof(query), "UPDATE players SET (money='%d', level='%d', admin='%d', interior='%d') WHERE name='%s'",PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pInt]);
	return 1;
}

public OnPlayerConnect(playerid)
{
	new query[256];
	GetPlayerName(playerid, PlayerInfo[playerid][pName], MAX_PLAYER_NAME);
	format(query, sizeof(query), "SELECT * FROM players WHERE name='%s'", PlayerInfo[playerid][pName]);
	mysql_query(query, PLAYER_CONNECT, playerid, SQLPtr);
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
	return 1;
}

public OnQueryFinish(query[], resultid, extraid, connectionHandle)
{
	new string[256];
	printf("Query: %d on connection %d finished:%s", resultid, connectionHandle, query);
	switch(resultid)
	{
	    case PLAYER_CONNECT:
	    {
			mysql_store_result(SQLPtr);
			printf("MySQL Name Rows: %d", mysql_num_rows(SQLPtr));
			SendClientMessage(extraid, COLOR_YELLOW, "Welcome to High Definition Roleplay!");
			if(mysql_num_rows(SQLPtr) > 1)
			{
			    SendClientMessage(extraid, COLOR_YELLOW, "Account Name Locked for Security Reasons, please come back later!");
			}
			else if(mysql_num_rows(SQLPtr))
			{
   				gPlayerAccount[extraid] = 1;
	   		  	SendClientMessage(extraid, COLOR_LIGHTYELLOW, "* Note: This account is registered. You need to login before you can spawn. *");
				ShowPlayerDialog(extraid,1,DIALOG_STYLE_INPUT,"Login Box","Enter your password here.","Login","Quit");
			}
			else
			{
				gPlayerAccount[extraid] = 0;
				SendClientMessage(extraid,COLOR_LIGHTYELLOW,"* Note: You dont have an account. Please register by typing your account password in the box! *");
        		ShowPlayerDialog(extraid,2,DIALOG_STYLE_INPUT,"Register Box","Think of a password and enter it here.","Register","Quit");
			}
		}
		case PLAYER_LOGIN:
		{
		    new key[64], idx;
			mysql_store_result(SQLPtr);
			mysql_fetch_row_format(string," ",SQLPtr);
			strtok(string, idx);
			strtok(string, idx);
			key = strtok(string, idx);
   			print(string);
			if(strcmp(key, PlayerInfo[extraid][pKey], false) == 0)
			{
			    PlayerInfo[extraid][pLevel] = strval(strtok(string, idx));
			    PlayerInfo[extraid][pMoney] = strval(strtok(string, idx));
			    PlayerInfo[extraid][pAdmin] = strval(strtok(string, idx));
			    PlayerInfo[extraid][pInt] = strval(strtok(string, idx));
			    PlayerInfo[extraid][pVirtual] = strval(strtok(string, idx));
			    PlayerInfo[extraid][pLocal] = strval(strtok(string, idx));
			    OnPlayerUpdate(extraid);
			    SpawnPlayer(extraid);
			    gPlayerLogged[extraid] = 1;
			}
			else
			{
			    ShowPlayerDialog(extraid,1,DIALOG_STYLE_INPUT,"Login Box","Wrong password, please enter your password.","Login","Quit");
			}
		}
		case VEHICLE_LOAD:
		{
		    mysql_store_result(SQLPtr);
		    if(extraid == 333)
		    {
		        printf("MySQL Vehicle Rows: %d", mysql_num_rows(SQLPtr));
		    	for(new c = 0; c < mysql_num_rows(SQLPtr); c++)
		    	{
		    	    format(string, sizeof(string), "SELECT * FROM vehicles WHERE id = '%d'", c);
					mysql_query(string, VEHICLE_LOAD);
				}
			}
	        new id,model,Float:x,Float:y,Float:z,Float:o,c1,c2, idx;
	        mysql_fetch_row_format(string, " ", SQLPtr);
	        id = strval(strtok(string, idx));
	        strval(strtok(string,idx));
	        model = strval(strtok(string, idx));
	        x = strval(strtok(string, idx));
	        y = strval(strtok(string, idx));
	        z = strval(strtok(string, idx));
	        o = strval(strtok(string, idx));
	        c1 = strval(strtok(string, idx));
			c2 = strval(strtok(string, idx));
			if(model > 400 && model < 611)
			{
	        	CreateVehicle(model,x,y,z,o,c1,c2, 300);
			}
			else
			{
				printf("DEBUG: Error on vehicle SQLID %d, invalid model.", id);
			}
		}
	}
	mysql_store_result(SQLPtr);
	mysql_free_result(SQLPtr);
}

public OnPlayerSpawn(playerid)
{
	return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
	return 1;
}

public OnVehicleSpawn(vehicleid)
{
	return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
	return 1;
}

public OnPlayerText(playerid, text[])
{
	new sendername[MAX_PLAYER_NAME], string[256];
	if(realchat)
	{
	    if(gPlayerLogged[playerid] == 0)
	    {
	        return 0;
      	}
		GetPlayerName(playerid, sendername, sizeof(sendername));
		format(string, sizeof(string), "%s says: %s", sendername, text);
		ProxDetector(20.0, playerid, string,COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_FADE4,COLOR_FADE5);
		return 0;
	}
	return 0;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
	new string[256], idx, playername[MAX_PLAYER_NAME], sendername[MAX_PLAYER_NAME], giveplayername[MAX_PLAYER_NAME], giveplayer, cmd[128], tmp[256];
	cmd = strtok(cmdtext, idx);
	/*
		Help topics
		/help (cmd, roleplay, rules, tutorial)
	*/
	if(strcmp(cmd, "/help", true) == 0)
	{
		new help[256];
		help = strtok(cmdtext, idx);

		if(!strlen(help))
		{
			SendClientMessage(playerid, COLOR_WHITE, "* Wrong syntax, usage: /help (topic) *");
			SendClientMessage(playerid, COLOR_GRAD1, "* Current topics: cmd, roleplay, rules, tutorial *");
			return 1;
		}

		if(strcmp(help, "roleplay", true) == 0 || strcmp(help, "rp", true) == 0)
		{
			SendClientMessage(playerid, COLOR_GRAD1, "For more information about the server and basic roleplay,");
			SendClientMessage(playerid, COLOR_GRAD1, "check our forums.");
			return 1;
		}
		else if(strcmp(help, "cmd", true) == 0)
		{

			SendClientMessage(playerid, COLOR_WHITE, "* GENERAL   | /help, /stats, /report, /o");
			SendClientMessage(playerid, COLOR_WHITE, "* ECONOMY  | /pay, /balance, /withdraw, /deposit");
			if(PlayerInfo[playerid][pAdmin] > 0)
			{
				SendClientMessage(playerid, COLOR_WHITE, "* ADMIN        | For the list of admin commands type /help admin");
				return 1;
			}
			return 1;
		}
		else if(strcmp(help, "rules", true) == 0)
		{
			SendClientMessage(playerid, COLOR_GRAD1, "Our rules can be found at our website, www.hd-rp.com.");
			SendClientMessage(playerid, COLOR_GRAD1, "* Note: You need to agree with our rules and terms within 3 days after you registered. *");
			return 1;
		}
		else if(strcmp(help, "tutorial", true) == 0)
		{
			SendClientMessage(playerid, COLOR_GRAD1, "This will force you to re-take the tutorial, you will be freezed for atleast 20 seconds.");
			SendClientMessage(playerid, COLOR_WHITE, "Are you sure you want to take the tutorial again? (yes, no)");
			
		    if(strcmp(tmp, "yes", true))
		    {
				TogglePlayerControllable(playerid, 0);
				SetTimer("ReTutorial",20000,false);
				format(string, sizeof(string), "* Note: %s is about to re-take the tutorial, admins are notified. *", sendername);
				ProxDetector(10.0, playerid, string, COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW);
				
				return 1;
			}
			else
			{
			    SendClientMessage(playerid, COLOR_WHITE, "You'r request to re-take the tutorial was canceled.");
			}
			return 1;
		}
		else if(strcmp(help, "admin", true) == 0)
		{
			if(PlayerInfo[playerid][pAdmin] > 1)
			{
				SendClientMessage(playerid, COLOR_WHITE, "* ADMIN (1)   | /goto, /kick, /prison, /a, /check, /warn, /respawncar, /forcetut");
				if(PlayerInfo[playerid][pAdmin] > 2)
				{
					SendClientMessage(playerid, COLOR_WHITE, "* ADMIN (2)   | /freeze, /unfreeze, /unprison, /spectate, /execute,/fix, /delcar");
					if(PlayerInfo[playerid][pAdmin] > 3)
					{
						SendClientMessage(playerid, COLOR_WHITE, "* ADMIN (3)   | /event, /teleport, /gethere, /forceskin, /gotohouse, /gotocar");
						if(PlayerInfo[playerid][pAdmin] > 4)
						{
							SendClientMessage(playerid, COLOR_WHITE, "* ADMIN (4)   | /logoutpl, /logoutall, /removehouse, /movehouse, /acar, /sethp, /setarmor, /givegun");
							SendClientMessage(playerid, COLOR_WHITE, "* ADMIN (4)   | /givemoney, /money, /weather, /tod, /mole");
							if(PlayerInfo[playerid][pAdmin] > 5)
							{
								SendClientMessage(playerid, COLOR_WHITE, "* ADMIN (5)   | /makeadmin, /startlotto, /asay, /cnn, /gmx, /setstat");
						 	}
						}
					}
				}
			}
			return 1;
		}
		else
		{
			return 0;
		}
	}
	/*
		Administrator commands
		When not admin; SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You are not eligible to use this command! *");
	*/
	if (strcmp("/gmx", cmd, true, 10) == 0)
	{
	    if(PlayerInfo[playerid][pAdmin] > 5)
	    {
		    SendClientMessage(playerid, COLOR_LIGHTBLUE, "The server will restart.");
			OnGameModeExit();
		}
		else
		{
		    SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You are not eligible to use this command! *");
		    SendClientMessage(playerid, COLOR_WHITE, "* Hint: For a complete list of available commands type /help *");
		}
		return 1;
	}
	/*
		Teleport functions and locations
		/teleport (location), /goto, /gethere
	*/
	if(strcmp(cmd, "/teleport", true) == 0)
	{
		if(IsPlayerConnected(playerid))
		{
			if(PlayerInfo[playerid][pAdmin] > 2)
			{
			    tmp = strtok(cmdtext, idx);
			    if(!strlen(tmp))
			    {
				    SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Usage: /teleport (location). *");
				    SendClientMessage(playerid, COLOR_WHITE, "* Available locations: PD, Airport, Bank, Hospital, Dillimore *");
				    SendClientMessage(playerid, COLOR_WHITE, "* Available locations: Gym, Stadium, SF, LV *");
				    return 1;
				}
				else if(!strcmp(tmp, "pd", true) || !strcmp(tmp, "police", true))
				{
					if(GetPlayerState(playerid) == 2)
					{
						new TempVeh = GetPlayerVehicleID(playerid);
						LinkVehicleToInterior(TempVeh, 0);
						SetVehiclePos(TempVeh, 1529.6,-1691.2,13.3);
					}
					else
					{
						SetPlayerPos(playerid, 1529.6,-1691.2,13.3);
					}

					SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You have been teleported to The Police Department. *");

					SetPlayerInterior(playerid, 0);
					PlayerInfo[playerid][pInt] = 0;

					SetPlayerVirtualWorld(playerid, 0);
					PlayerInfo[playerid][pVirtual] = 0;
				    return 1;
				}
				else if(!strcmp(tmp, "newbie", true) || !strcmp(tmp, "airport", true))
				{
					if(GetPlayerState(playerid) == 2)
					{
						new TempVeh = GetPlayerVehicleID(playerid);
						LinkVehicleToInterior(TempVeh, 0);

						SetVehiclePos(TempVeh, 1627.1173,-2310.6636,13.5561);
					}
					else
					{
						SetPlayerPos(playerid, 1627.1173,-2310.6636,13.5561);
					}

					SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You have been teleported to The Airport. *");

					SetPlayerInterior(playerid, 0);
					PlayerInfo[playerid][pInt] = 0;

					SetPlayerVirtualWorld(playerid, 0);
					PlayerInfo[playerid][pVirtual] = 0;
				    return 1;
				}
				else if(!strcmp(tmp, "bank", true) || !strcmp(tmp, "money", true))
				{
					if(GetPlayerState(playerid) == 2)
					{
						new TempVeh = GetPlayerVehicleID(playerid);
						LinkVehicleToInterior(TempVeh, 0);

						SetVehiclePos(TempVeh, 1461.0757,-1043.0641,23.8281);
					}
					else
					{
						SetPlayerPos(playerid, 1461.0757,-1043.0641,23.8281);
					}

					SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You have been teleported to The Bank. *");

					SetPlayerInterior(playerid, 0);
					PlayerInfo[playerid][pInt] = 0;

					SetPlayerVirtualWorld(playerid, 0);
					PlayerInfo[playerid][pVirtual] = 0;
				    return 1;
				}
				else if(!strcmp(tmp, "hp", true) || !strcmp(tmp, "hospital", true))
				{
					if(GetPlayerState(playerid) == 2)
					{
						new TempVeh = GetPlayerVehicleID(playerid);
						LinkVehicleToInterior(TempVeh, 0);

						SetVehiclePos(TempVeh, 1179.2675,-1329.9879,14.14031);
					}
					else
					{
						SetPlayerPos(playerid, 1179.2675,-1329.9879,14.1403);
					}

					SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You have been teleported to The Hospital. *");

					SetPlayerInterior(playerid, 0);
					PlayerInfo[playerid][pInt] = 0;

					SetPlayerVirtualWorld(playerid, 0);
					PlayerInfo[playerid][pVirtual] = 0;
				    return 1;
				}
				else if(!strcmp(tmp, "dillimore", true) || !strcmp(tmp, "dilli", true))
				{
					if(GetPlayerState(playerid) == 2)
					{
						new TempVeh = GetPlayerVehicleID(playerid);
						LinkVehicleToInterior(TempVeh, 0);
						SetVehiclePos(TempVeh, 650.0621,-546.2467,16.2838);
					}
					else
					{
						SetPlayerPos(playerid, 650.0621,-546.2467,16.2838);
					}
					SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You have been teleported to Dillimore. *");
					SetPlayerInterior(playerid, 0);
					PlayerInfo[playerid][pInt] = 0;

					SetPlayerVirtualWorld(playerid, 0);
					PlayerInfo[playerid][pVirtual] = 0;
				    return 1;
				}
				else if(!strcmp(tmp, "gym", true) || !strcmp(tmp, "fight", true))
				{
					if(GetPlayerState(playerid) == 2)
					{
						new TempVeh = GetPlayerVehicleID(playerid);
						LinkVehicleToInterior(TempVeh, 0);

						SetVehiclePos(TempVeh, 2228.3411,-1742.3685,13.5446);
					}
					else
					{
						SetPlayerPos(playerid, 2228.3411,-1742.3685,13.5446);
					}

					SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You have been teleported to The Gym. *");

					SetPlayerInterior(playerid, 0);
					PlayerInfo[playerid][pInt] = 0;

					SetPlayerVirtualWorld(playerid, 0);
					PlayerInfo[playerid][pVirtual] = 0;
				    return 1;
				}
				else if(!strcmp(tmp, "stadium", true) || !strcmp(tmp, "race", true))
				{
					if(GetPlayerState(playerid) == 2)
					{
						new TempVeh = GetPlayerVehicleID(playerid);
						LinkVehicleToInterior(TempVeh, 0);

						SetVehiclePos(TempVeh, 2719.8882,-1841.8689,10.3125);
					}
					else
					{
						SetPlayerPos(playerid, 2719.8882,-1841.8689,10.3125);
					}

					SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You have been teleported to The Stadium. *");

					SetPlayerInterior(playerid, 0);
					PlayerInfo[playerid][pInt] = 0;

					SetPlayerVirtualWorld(playerid, 0);
					PlayerInfo[playerid][pVirtual] = 0;
				    return 1;
				}
				else if(!strcmp(tmp, "sanfierro", true) || !strcmp(tmp, "sf", true))
				{
					if(GetPlayerState(playerid) == 2)
					{
						new TempVeh = GetPlayerVehicleID(playerid);
						LinkVehicleToInterior(TempVeh, 0);

						SetVehiclePos(TempVeh, -1407.3066,-305.9693,14.1484);
					}
					else
					{
						SetPlayerPos(playerid, -1407.3066,-305.9693,14.1484);
					}

					SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You have been teleported to San Fierro. *");

					SetPlayerInterior(playerid, 0);
					PlayerInfo[playerid][pInt] = 0;

					SetPlayerVirtualWorld(playerid, 0);
					PlayerInfo[playerid][pVirtual] = 0;
				    return 1;
				}
				else if(!strcmp(tmp, "lv", true) || !strcmp(tmp, "lasventuras", true))
				{
					if(GetPlayerState(playerid) == 2)
					{
						new TempVeh = GetPlayerVehicleID(playerid);
						LinkVehicleToInterior(TempVeh, 0);

						SetVehiclePos(TempVeh, 1697.6373,1415.1118,10.7561);
					}
					else
					{
						SetPlayerPos(playerid, 1697.6373,1415.1118,10.7561);
					}

					SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You have been teleported to Las Venturas. *");

					SetPlayerInterior(playerid, 0);
					PlayerInfo[playerid][pInt] = 0;

					SetPlayerVirtualWorld(playerid, 0);
					PlayerInfo[playerid][pVirtual] = 0;
				    return 1;
				}
				else
				{
				    SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: Unknown location, failed to teleport. *");
				    SendClientMessage(playerid, COLOR_WHITE, "* Available locations: PD, Airport, Bank, Hospital, Dillimore *");
				    SendClientMessage(playerid, COLOR_WHITE, "* Available locations: Gym, Stadium, SF, LV *");
				    return 1;
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You are not eligible to use this command! *");
				SendClientMessage(playerid, COLOR_WHITE, "* Hint: For a complete list of available commands type /help *");
				return 1;
			}
		}
	}
	if(strcmp(cmd, "/gethere", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD1, "* Wrong syntax, usage: /gethere (playerid) *");
				return 1;
			}
			new Float:plocx,Float:plocy,Float:plocz;
			new plo;
			plo = ReturnUser(tmp);
			new intid;
			intid = GetPlayerInterior(playerid);
			if (IsPlayerConnected(plo))
			{
			    if(plo != INVALID_PLAYER_ID)
			    {
					if (PlayerInfo[playerid][pAdmin] >= 3)
					{
						GetPlayerPos(playerid, plocx, plocy, plocz);
						if(intid > 0)
						{
							SetPlayerInterior(plo,intid);
							PlayerInfo[plo][pInt] = intid;
							PlayerInfo[plo][pLocal] = PlayerInfo[playerid][pLocal];
						}
						if(intid == 0)
						{
							SetPlayerInterior(plo,0);
						}
						if (GetPlayerState(plo) == 2)
						{
							new tmpcar = GetPlayerVehicleID(plo);
							LinkVehicleToInterior(tmpcar,intid);
							PlayerInfo[plo][pInt] = intid;
							PlayerInfo[plo][pLocal] = PlayerInfo[playerid][pLocal];
							SetVehiclePos(tmpcar, plocx, plocy+4, plocz);
						}
						else
						{
							SetPlayerPos(plo,plocx,plocy+2, plocz);
						}
						SendClientMessage(plo, COLOR_LIGHTYELLOW, "* Note: You have been teleported by an admin.");
					}
					else
					{
					    SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You are not eligible to use this command! *");
					    SendClientMessage(playerid, COLOR_WHITE, "* Hint: For a complete list of available commands type /help *");
					}
				}
			}
			else
			{
				format(string, sizeof(string), "* Note: %d is not an active player. *", plo);
				SendClientMessage(playerid, COLOR_GRAD1, string);
			}
		}
		return 1;
	}
	if(strcmp(cmd, "/goto", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
                SendClientMessage(playerid, COLOR_GRAD1, "* Wrong syntax, usage: /goto (playerid) *");
				return 1;
			}
			new Float:plocx,Float:plocy,Float:plocz;
			new plo;
			plo = ReturnUser(tmp);
			new intid;
			intid = GetPlayerInterior(plo);
			if (IsPlayerConnected(plo))
			{
			    if(plo != INVALID_PLAYER_ID)
			    {
					if (PlayerInfo[playerid][pAdmin] >= 1)
					{
						GetPlayerPos(plo, plocx, plocy, plocz);
						if(intid > 0)
						{
							SetPlayerInterior(playerid,intid);
							PlayerInfo[playerid][pInt] = PlayerInfo[plo][pInt];
							PlayerInfo[playerid][pLocal] = PlayerInfo[plo][pLocal];
						}
						if(intid == 0)
						{
							SetPlayerInterior(playerid,0);
						}
						if(plocz > 530.0 && PlayerInfo[plo][pInt] == 0)
						{
							SetPlayerInterior(playerid,1);
							PlayerInfo[playerid][pInt] = 1;
						}
						if (GetPlayerState(playerid) == 2)
						{
							new tmpcar = GetPlayerVehicleID(playerid);
							LinkVehicleToInterior(tmpcar, intid);
							SetVehiclePos(tmpcar, plocx, plocy+4, plocz);
						}
						else if(GetPlayerState(plo) == 2 && GetPlayerState(playerid) != 2)
						{
						    new tmpcar = GetPlayerVehicleID(plo);
						    PutPlayerInVehicle(playerid, tmpcar, 1);
						}
						else
						{
							SetPlayerPos(playerid,plocx,plocy+2, plocz+1);
						}
                        SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You have been teleported to the player.");
					}
					else
					{
					    SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You are not eligible to use this command! *");
					    SendClientMessage(playerid, COLOR_WHITE, "* Hint: For a complete list of available commands type /help *");
					}
				}
			}
			else
			{
				format(string, sizeof(string), "* Note: %d is not an active player. *", plo);
				SendClientMessage(playerid, COLOR_GRAD1, string);
			}
		}
		return 1;
	}
	/*
		Common chat commands for all players
		/me, /shout, /low
	*/
	if(strcmp(cmd, "/me", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(gPlayerLogged[playerid] == 0)
	        {
	            SendClientMessage(playerid, COLOR_WHITE, "You are not logged in yet, unable to perform action!");
	            return 1;
	        }
			GetPlayerName(playerid, sendername, sizeof(sendername));
			new length = strlen(cmdtext);
			while ((idx < length) && (cmdtext[idx] <= ' '))
			{
				idx++;
			}
			new offset = idx;
			new result[64];
			while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
			{
				result[idx - offset] = cmdtext[idx];
				idx++;
			}
			result[idx - offset] = EOS;
			if(!strlen(result))
			{
				SendClientMessage(playerid, COLOR_GRAD1, "* Wrong syntax, usage: /me (action) *");
				return 1;
			}
			format(string, sizeof(string), "* %s %s", sendername, result);
			ProxDetector(20.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
			printf("%s", string);
		}
		return 1;
	}
	if(strcmp(cmd, "/shout", true) == 0 || strcmp(cmd, "/s", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(gPlayerLogged[playerid] == 0)
	        {
	            SendClientMessage(playerid, COLOR_WHITE, "You are not logged in yet, unable to perform action!");
	            return 1;
	        }
			GetPlayerName(playerid, sendername, sizeof(sendername));
			new length = strlen(cmdtext);
			while ((idx < length) && (cmdtext[idx] <= ' '))
			{
				idx++;
			}
			new offset = idx;
			new result[64];
			while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
			{
				result[idx - offset] = cmdtext[idx];
				idx++;
			}
			result[idx - offset] = EOS;
			if(!strlen(result))
			{
				SendClientMessage(playerid, COLOR_GRAD1, "* Wrong syntax, usage: /shout (message) *");
				return 1;
			}
			format(string, sizeof(string), "%s shouts: %s!", sendername, result);
			ProxDetector(25.0, playerid, string,COLOR_WHITE,COLOR_WHITE,COLOR_WHITE,COLOR_FADE1,COLOR_FADE2);
			printf("%s", string);
		}
		return 1;
	}
	if(strcmp(cmd, "/low", true) == 0 || strcmp(cmd, "/l", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(gPlayerLogged[playerid] == 0)
	        {
	            SendClientMessage(playerid, COLOR_WHITE, "You are not logged in yet, unable to perform action!");
	            return 1;
	        }
			GetPlayerName(playerid, sendername, sizeof(sendername));
			new length = strlen(cmdtext);
			while ((idx < length) && (cmdtext[idx] <= ' '))
			{
				idx++;
			}
			new offset = idx;
			new result[64];
			while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
			{
				result[idx - offset] = cmdtext[idx];
				idx++;
			}
			result[idx - offset] = EOS;
			if(!strlen(result))
			{
				SendClientMessage(playerid, COLOR_GRAD1, "* Wrong syntax, usage: /low (message) *");
				return 1;
			}
			format(string, sizeof(string), "%s says (low): %s!", sendername, result);
			ProxDetector(5.0, playerid, string,COLOR_WHITE,COLOR_WHITE,COLOR_WHITE,COLOR_FADE1,COLOR_FADE2);
			printf("%s", string);
		}
		return 1;
	}
	if(strcmp(cmd, "/b", true) == 0)//local ooc
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(gPlayerLogged[playerid] == 0)
	        {
	            SendClientMessage(playerid, COLOR_WHITE, "You are not logged in yet, unable to perform action!");
	            return 1;
	        }
			GetPlayerName(playerid, sendername, sizeof(sendername));
			new length = strlen(cmdtext);
			while ((idx < length) && (cmdtext[idx] <= ' '))
			{
				idx++;
			}
			new offset = idx;
			new result[64];
			while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
			{
				result[idx - offset] = cmdtext[idx];
				idx++;
			}
			result[idx - offset] = EOS;
			format(string, sizeof(string), "%s says: (( %s ))", sendername, result);
			ProxDetector(20.0, playerid, string,COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_FADE4,COLOR_FADE5);
			printf("%s", string);
		}
	}
	if(strcmp(cmd, "/fix", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(PlayerInfo[playerid][pAdmin] < 2)
			{
   				SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You are not eligible to use this command! *");
				SendClientMessage(playerid, COLOR_WHITE, "* Hint: For a complete list of available commands type /help *");
			    return 1;
			}
			if(IsPlayerInAnyVehicle(playerid))
			{
			    SetVehicleHealth(GetPlayerVehicleID(playerid), 1000.0);
			    SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You'r vehicle has been fixed. *");
			}
		}
		return 1;
	}
	if(strcmp(cmd, "/sethp", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_WHITE, "* Wrong syntax, usage: /sethp (playerid) (health) *");
				return 1;
			}
			new playa;
			new health;
			playa = ReturnUser(tmp);
			tmp = strtok(cmdtext, idx);
			health = strval(tmp);
			if (PlayerInfo[playerid][pAdmin] >= 4)
			{
			    if(IsPlayerConnected(playa))
			    {
			        if(playa != INVALID_PLAYER_ID)
			        {
						SetPlayerHealth(playa, health);
					}
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You are not eligible to use this command! *");
				SendClientMessage(playerid, COLOR_WHITE, "* Hint: For a complete list of available commands type /help *");
			}
		}
		return 1;
	}
	if(strcmp(cmd, "/setarmor", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_WHITE, "* Wrong syntax, usage: /sethp (playerid) (health) *");
				return 1;
			}
			new playa;
			new health;
			playa = ReturnUser(tmp);
			tmp = strtok(cmdtext, idx);
			health = strval(tmp);
			if (PlayerInfo[playerid][pAdmin] >= 4)
			{
			    if(IsPlayerConnected(playa))
			    {
			        if(playa != INVALID_PLAYER_ID)
			        {
						SetPlayerArmour(playa, health);
					}
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You are not eligible to use this command! *");
				SendClientMessage(playerid, COLOR_WHITE, "* Hint: For a complete list of available commands type /help *");
			}
		}
		return 1;
	}
	if(strcmp(cmd, "/execute", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_WHITE, "* Wrong syntax, usage: /execute (playerid) *");
				return 1;
			}
			new playa;
			playa = ReturnUser(tmp);
			tmp = strtok(cmdtext, idx);
			if (PlayerInfo[playerid][pAdmin] >= 4)
			{
			    if(IsPlayerConnected(playa))
			    {
			        if(playa != INVALID_PLAYER_ID)
			        {
						SetPlayerHealth(playa, 0);
					}
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You are not eligible to use this command! *");
				SendClientMessage(playerid, COLOR_WHITE, "* Hint: For a complete list of available commands type /help *");
			}
		}
		return 1;
	}
	if(strcmp(cmd, "/ooc", true) == 0 || strcmp(cmd, "/o", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(gPlayerLogged[playerid] == 0)
	        {
	            SendClientMessage(playerid, COLOR_WHITE, "You are not logged in yet, unable to perform action!");
	            return 1;
	        }
			GetPlayerName(playerid, sendername, sizeof(sendername));
			new length = strlen(cmdtext);
			while ((idx < length) && (cmdtext[idx] <= ' '))
			{
				idx++;
			}
			new offset = idx;
			new result[64];
			while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
			{
				result[idx - offset] = cmdtext[idx];
				idx++;
			}
			result[idx - offset] = EOS;
			if(!strlen(result))
			{
				SendClientMessage(playerid, COLOR_GRAD1, "* Wrong syntax, usage: /o (message) *");
				return 1;
			}
			format(string, sizeof(string), "(( %s: %s ))", sendername, result);
			SendClientMessageToAll(COLOR_OOC, string);
			printf("%s", string);
		}
		return 1;
	}
	if(strcmp(cmd, "/admin", true) == 0 || strcmp(cmd, "/a", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			GetPlayerName(playerid, sendername, sizeof(sendername));
			new length = strlen(cmdtext);
			while ((idx < length) && (cmdtext[idx] <= ' '))
			{
				idx++;
			}
			new offset = idx;
			new result[64];
			while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
			{
				result[idx - offset] = cmdtext[idx];
				idx++;
			}
			result[idx - offset] = EOS;
			if(!strlen(result))
			{
				SendClientMessage(playerid, COLOR_GRAD1, "* Wrong syntax, usage: /a (message) *");
				return 1;
			}
			new adminlvl;
			adminlvl = PlayerInfo[playerid][pAdmin];
			
			format(string, sizeof(string), "* Admin %s [%d]: %s *", sendername, adminlvl, result);
			if (PlayerInfo[playerid][pAdmin] >= 1)
			{
				SendAdminMessage(COLOR_ADMINCHAT, string);
			}
			printf(string);
		}
		return 1;
	}
	if(strcmp(cmdtext, "/delcar", true) == 0)
	{
		if(IsPlayerConnected(playerid))
	    {
	        if(PlayerInfo[playerid][pAdmin] < 2)
			{
				SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You are not eligible to use this command! *");
   				SendClientMessage(playerid, COLOR_WHITE, "* Hint: For a complete list of available commands type /help *");
			    return 1;
			}
            new currentveh;
            currentveh = GetPlayerVehicleID(playerid);
            DestroyVehicle(currentveh);
            return 1;
 		}
	}
	if(strcmp(cmd, "/veh", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if (PlayerInfo[playerid][pAdmin] < 2)
			{
				SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You are not eligible to use this command! *");
   				SendClientMessage(playerid, COLOR_WHITE, "* Hint: For a complete list of available commands type /help *");
			    return 1;
			}
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD1, "* Wrong syntax, usage: /veh (model) (color1) (color2) *");
				return 1;
			}
			new car;
			car = strval(tmp);
			if(car < 400 || car > 611) { SendClientMessage(playerid, COLOR_YELLOW, "* Note: Invalid vehicle ID, must be between 411 and 600 *"); return 1; }
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD1, "* Wrong syntax, usage: /veh (model) (color1) (color2) *");
				return 1;
			}
			new color1;
			color1 = strval(tmp);
			if(color1 < 0 || color1 > 200) { SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: Invalid color ID, must be between 0-200 *"); return 1; }
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD1, "* Wrong syntax, usage: /veh (model) (color1) (color2) *");
				return 1;
			}
			new color2;
			color2 = strval(tmp);
			if(color2 < 0 || color2 > 200) { SendClientMessage(playerid, COLOR_YELLOW, "* Note: Invalid color ID, must be between 0-200 *"); return 1; }
		 	new Float:X,Float:Y,Float:Z;
	    	GetPlayerPos(playerid,X,Y,Z);
	    	new intid, Float:angle;
	    	intid = GetPlayerInterior(playerid);
	    	GetPlayerFacingAngle(playerid, angle);
			new carid = CreateVehicle(car, X,Y,Z, angle, color1, color2, 1800);
			format(string, sizeof(string), "INSERT INTO vehicles (type,model,x,y,z,o,color1,color2) values (2,%d,%f,%f,%f,%f,%d,%d)", car,X,Y,Z,angle,color1,color2);
			mysql_query(string);
	    	PutPlayerInVehicle(playerid, carid, 0);
	  		LinkVehicleToInterior(carid, intid);
			format(string, sizeof(string), "Vehicle %d spawned.", carid);
			SendClientMessage(playerid, COLOR_GREY, string);
		}
		return 1;
	}
	if(strcmp(cmd, "/givegun", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(PlayerInfo[playerid][pAdmin] > 3)
	        {
				tmp = strtok(cmdtext, idx);
				if(!strlen(tmp))
				{
					SendClientMessage(playerid, COLOR_LIGHTYELLOW, "USAGE: /givegun (playerid/PartOfName) (weaponid(eg. 46 = Parachute))");
					SendClientMessage(playerid, COLOR_LIGHTYELLOW, "3(Club) 4(knife) 5(bat) 6(Shovel) 7(Cue) 8(Katana) 10-13(Dildo) 14(Flowers)");
					SendClientMessage(playerid, COLOR_LIGHTYELLOW, "16(Grenades) 18(Molotovs) 22(Pistol) 23(SPistol)");
					SendClientMessage(playerid, COLOR_LIGHTYELLOW, "24(Eagle) 25(shotgun) 27(spas12) 29(MP5) 30(AK47) 31(M4) 33(Rifle) 34(Sniper)");
					SendClientMessage(playerid, COLOR_LIGHTYELLOW, " 37(Flamethrower) 41(spray) 42(exting) 43(Camera) 46(Parachute)");
					return 1;
				}
				new playa;
				new gun;
				playa = ReturnUser(tmp);
				tmp = strtok(cmdtext, idx);
				gun = strval(tmp);
				if(gun < 1||gun > 46) { SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: Wrong Weapon ID."); return 1; }
                if(IsPlayerConnected(playa))
			    {
			        if(playa != INVALID_PLAYER_ID)
			        {
/*			            if(gun < 10 && gun > 1)  PlayerInfo[playa][pGun1] = gun;
			            if(gun < 25 && gun > 21) PlayerInfo[playa][pGun2] = gun;
			            if(gun < 28 && gun > 24) PlayerInfo[playa][pGun3] = gun;
			            if(gun < 30 && gun > 27 || gun == 32) PlayerInfo[playa][pGun4] = gun;
			            if(gun < 32 && gun > 29) PlayerInfo[playa][pGun5] = gun;
			            if(gun < 35 && gun > 32) PlayerInfo[playa][pGun6] = gun; */
						GivePlayerWeapon(playa, gun, 65000);
						return 1;
					}
					else
					{
						SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: There is no such player.");
						return 1;
					}
				}
				else
				{
					SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: Player is not connected.");
					return 1;
				}
			}
		}
		return 0;
	}
	return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
	return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
	return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
	return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
	return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
	return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
	return 1;
}

public OnRconCommand(cmd[])
{
	return 1;
}

public OnPlayerRequestSpawn(playerid)
{
	return 1;
}

public OnObjectMoved(objectid)
{
	return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
	return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
	if (pickupid == BankEnter)
	{
		SetPlayerPos(playerid,2305.0930,-16.1713,26.7422);
		PlayerInfo[playerid][pLocal] = 201;
	}
	if (pickupid == BankExit)
	{
		SetPlayerPos(playerid,1462.395751,-1012.391174,26.843799);
		PlayerInfo[playerid][pLocal] = 255;
	}
	return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
	return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
	return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
	return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
	return 1;
}

public OnPlayerExitedMenu(playerid)
{
	return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
	return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
	return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
	return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
	return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
	return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 1)
	{
	    if(!response)
	    {
	        SendClientMessage(playerid, COLOR_GREY,"You have to login to play on the server!");
			Kick(playerid);
			return 0;
		}
        new tmppass[64];
        if(!IsPlayerConnected(playerid))
		{
		    SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: Please wait until fully connected! *");
		    return 0;
		}
		if(gPlayerLogged[playerid] == 1)
		{
			SendClientMessage(playerid, COLOR_LIGHTYELLOW, "* Note: You are already logged in, you can't login twice! *");
			return 0;
		}
		if(!strlen(inputtext))
		{
			SendClientMessage(playerid, COLOR_GRAD1, "* Wrong syntax, usage: Just type the god damn password ffs! *");
			ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Login Box","You can enter your password here.","Login","Quit");
			return 0;
		}
		strmid(tmppass, inputtext, 0, strlen(inputtext), 255);
		Encrypt(tmppass);
		OnPlayerLogin(playerid,tmppass);
		return 1;
	}
	if(dialogid == 2)
	{
	    if(!response)
	    {
	        SendClientMessage(playerid, COLOR_GREY,"You have to register to play on the server!");
			Kick(playerid);
			return 0;
		}
		if(IsPlayerConnected(playerid))
	    {
	        if(gPlayerLogged[playerid] == 1)
			{
				SendClientMessage(playerid, COLOR_GRAD1, "* Note: You are already logged in, you can't login twice! *");
				return 0;
			}
	        new tmppass[64];
			if(!strlen(inputtext))
			{
				SendClientMessage(playerid, COLOR_GRAD1, "* Wrong syntax, usage: Just type the god damn password ffs! *");
				ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Register Box","You can enter your password here.","Register","Quit");
				return 0;
			}
			strmid(tmppass, inputtext, 0, strlen(inputtext), 255);
			Encrypt(tmppass);
			OnPlayerRegister(playerid,tmppass);
		}
		return 1;
	}
	return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
	return 1;
}

strtok(const string[], &index)
{
	new length = strlen(string);
	while ((index < length) && (string[index] <= ' '))
	{
		index++;
	}

	new offset = index;
	new result[20];
	while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
	{
		result[index - offset] = string[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}

public ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5)
{
	if(IsPlayerConnected(playerid))
	{
		new Float:posx, Float:posy, Float:posz;
		new Float:oldposx, Float:oldposy, Float:oldposz;
		new Float:tempposx, Float:tempposy, Float:tempposz;
		GetPlayerPos(playerid, oldposx, oldposy, oldposz);
		//radi = 2.0; //Trigger Radius
		for(new i = 0; i < MAX_PLAYERS; i++)
		{
			if(IsPlayerConnected(i))
			{
				GetPlayerPos(i, posx, posy, posz);
				tempposx = (oldposx -posx);
				tempposy = (oldposy -posy);
				tempposz = (oldposz -posz);
				//printf("DEBUG: X:%f Y:%f Z:%f",posx,posy,posz);
				if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
				{
					SendClientMessage(i, col1, string);
				}
				else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
				{
					SendClientMessage(i, col2, string);
				}
				else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
				{
					SendClientMessage(i, col3, string);
				}
				else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
				{
					SendClientMessage(i, col4, string);
				}
				else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
				{
					SendClientMessage(i, col5, string);
				}
			}
			else
			{
				SendClientMessage(i, col1, string);
			}
		}
	}//not connected
	return 1;
}

public ProxDetectorS(Float:radi, playerid, targetid)
{
    if(IsPlayerConnected(playerid)&&IsPlayerConnected(targetid))
	{
		new Float:posx, Float:posy, Float:posz;
		new Float:oldposx, Float:oldposy, Float:oldposz;
		new Float:tempposx, Float:tempposy, Float:tempposz;
		GetPlayerPos(playerid, oldposx, oldposy, oldposz);
		//radi = 2.0; //Trigger Radius
		GetPlayerPos(targetid, posx, posy, posz);
		tempposx = (oldposx -posx);
		tempposy = (oldposy -posy);
		tempposz = (oldposz -posz);
		//printf("DEBUG: X:%f Y:%f Z:%f",posx,posy,posz);
		if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
		{
			return 1;
		}
	}
	return 0;
}

public PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
{
    if(IsPlayerConnected(playerid))
	{
		new Float:oldposx, Float:oldposy, Float:oldposz;
		new Float:tempposx, Float:tempposy, Float:tempposz;
		GetPlayerPos(playerid, oldposx, oldposy, oldposz);
		tempposx = (oldposx -x);
		tempposy = (oldposy -y);
		tempposz = (oldposz -z);
		//printf("DEBUG: X:%f Y:%f Z:%f",posx,posy,posz);
		if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
		{
			return 1;
		}
	}
	return 0;
}

